message("Setup and configure")

macx {
    include($$myPRIDIR/__osx.pri)
    myBUILDSUBDIR="OSX/$$myOSX-$$myOSXSTDLIBPATHCOMPONENT"
    CONFIG += macports
} else {
    message("REMOVE ME WHEN PROPERLY SETUP")
    myBUILDSUBDIR = FIX_ME_IN__setup.pri
}
# All these are subdirectories of OUT_PWD
DESTDIR = "$$myBUILDSUBDIR/dest"
OBJECTS_DIR = "$$myBUILDSUBDIR/objects"
MOC_DIR = "$$myBUILDSUBDIR/moc"
RCC_DIR = "$$myBUILDSUBDIR/rcc"
UI_DIR = "$$myBUILDSUBDIR/ui"
myDERIVEDSUBDIR = "$$myBUILDSUBDIR/derived"
INCLUDEPATH += "$$myDERIVEDSUBDIR"
DEPENDPATH += "$$myDERIVEDSUBDIR"

my3RDDESTDIR="$$my3RDDIR/Install"
macx {
    my3RDDESTDIR="$$my3RDDESTDIR/$$myBUILDSUBDIR"
} else {
    message("REMOVE THIS MESSAGE WHEN PROPERLY SETUP")
    my3RDDESTDIR="$$my3RDDESTDIR/FIX_ME_IN__setup.pri"
}

my3RDINCLUDEDIR = "$$my3RDDESTDIR/include"
my3RDLIBDIR = "$$my3RDDESTDIR/lib"
my3RDBINDIR = "$$my3RDDESTDIR/bin"
INCLUDEPATH += "$$my3RDINCLUDEDIR"
DEPENDPATH  += "$$my3RDINCLUDEDIR"

macx {
    QMAKE_MACOSX_DEPLOYMENT_TARGET=$$myOSX
    myCFLAGS+="-arch x86_64"
    QMAKE_CXXFLAGS="$$myCFLAGS -stdlib=$$myOSXSTDLIB"
    QMAKE_LFLAGS +="-stdlib=$$myOSXSTDLIB -Wl,-no_pie"
    LIBS += -L"$$my3RDLIBDIR"
} else {
    message("REMOVE THIS MESSAGE WHEN PROPERLY SETUP")
}
DEPENDPATH  += "$$my3RDLIBDIR"

#with_icu {
#    include($$myPRIDIR/_icu.pri)
#}
with_boost {
    include($$myPRIDIR/_boost.pri)
}
with_caspp {
    include($$myPRIDIR/caspp.pri)
}
with_paxer {
    include($$myPRIDIR/paxer.pri)
}

# Copies the given files to the destination directory
defineTest(myCopyToDestdir) {
    files = $$1

    for(FILE, files) {
        DDIR = $$DESTDIR

        # Replace slashes in paths with backslashes for Windows
        win32:FILE ~= s,/,\\,g
        win32:DDIR ~= s,/,\\,g

        QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
    }

    export(QMAKE_POST_LINK)
}

defineReplace(myPathRelativeToBase) {
    arg = $$1
    result = $$relative_path($$arg,$$myBASEDIR)
    return($$result)
}

myBASEDPROFILEPWD = $$myPathRelativeToBase($$_PRO_FILE_PWD_)
myBASEDOUTPWD = $$myPathRelativeToBase($$OUT_PWD)
myOUTPWDEDBASE = $$relative_path($$myBASEDIR,$$OUT_PWD)
#$$OUT_PWD/$$myOUTPWDEDBASE = $$myBASEDIR

defineReplace(myRelativeToBasePaths) {
    original_values = $$1
    original_values = $$unique(original_values)
    for(value, original_values) {
        exists($$value): {
            value = $$myPathRelativeToBase($$value)
            values += $$value
        }
    }
    return($$values)
}

defineReplace(my_WRT_PRO_FILE_PWD) {
    arg = $$1
    result = $$relative_path($$arg,$$_PRO_FILE_PWD_)
    return($$result)
}

defineReplace(my_WRT_PRO_FILE_PWD_s) {
    original_values = $$1
    original_values = $$unique(original_values)
    for(value, original_values) {
        exists($$value): {
            value = $$my_WRT_PRO_FILE_PWD($$value)
            values += $$value
        }
    }
    return($$values)
}

defineReplace(my_WRT_OUT_PWD) {
    arg = $$1
    result = $$relative_path($$arg,$$OUT_PWD)
    return($$result)
}

defineReplace(my_WRT_OUT_PWD_s) {
    original_values = $$1
    original_values = $$unique(original_values)
    for(value, original_values) {
        exists($$value): {
            value = $$my_WRT_OUT_PWD($$value)
            values += $$value
        }
    }
    return($$values)
}

HEADERS += \
    "$$myBASEDIR/shared/config.h" \
    "$$myBASEDIR/shared/macros.h" \
    "$$myBASEDIR/shared/wrap.h" \
